package org.ranshiyan.bean;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.ranshiyan.dao.OrderDao;
import org.ranshiyan.pojo.Orderx;
import org.ranshiyan.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SyncUserJob extends QuartzJobBean {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private OrderDao orderDao;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String userName= (String)jobExecutionContext.getJobDetail().getJobDataMap().get("userName");
        String blogUrl= (String)jobExecutionContext.getJobDetail().getJobDataMap().get("blogUrl");
        String blogRemark= (String)jobExecutionContext.getJobDetail().getJobDataMap().get("blogRemark");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("用户名称"+userName);
        System.out.println("博客地址"+blogUrl);
        System.out.println("博客信息"+blogRemark);
        System.out.println("当前时间"+simpleDateFormat.format(new Date()));

        /*List<Teacher> list = teacherService.list();*/
        List<Orderx> order = orderDao.getOrder();
        order.forEach(item->{
            item.setOrderType(3);
            QueryWrapper<Orderx> objectQueryWrapper = new QueryWrapper<>();
            objectQueryWrapper.eq("id",item.getId());
            orderDao.update(item,objectQueryWrapper);
        });
        System.out.println("当前请求时间"+System.currentTimeMillis()+"内容"+order);


        /*System.out.println("开启多线程");
        ExecutorService pool = Executors.newFixedThreadPool(5);
        pool.execute(new Runnable() {
            @Override
            public void run() {

            }
        });
        pool.execute(new Runnable() {
            @Override
            public void run() {

            }
        });
        pool.shutdown();
        *//*pool.awaitTermination();*//*
        pool.shutdownNow();*/
    }
}
